package cn.rubintry.hualahuala

import android.content.res.Configuration
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import com.youku.cloud.player.YoukuPlayer

class MainActivity : AppCompatActivity() {
    protected var player : YoukuPlayer?= null

    private lateinit var clContainer : ConstraintLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        clContainer = findViewById(R.id.clContainer)
        clContainer.setOnClickListener {
            player?.setDisplayContainer(findViewById(R.id.clContainer))
            player?.playVideo("XNDkyMzE4MDE1Ng==" , "6d75d19c77e2702e4b1d6745312ec47f")
        }

        player = YoukuPlayer(this)
        player?.onCreate()
        player?.start()

    }

    override fun onStart() {
        super.onStart()
        player?.onStart()
    }

    override fun onStop() {
        player?.onStop()
        super.onStop()
    }

    override fun onDestroy() {
        player?.onDestroy()
        super.onDestroy()
    }

    override fun onPause() {
        player?.onPause()
        super.onPause()
    }

    override fun onResume() {
        player?.onResume()
        super.onResume()
    }



    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        player?.onConfigurationChanged(newConfig)
    }

    override fun onWindowFocusChanged(hasFocus: Boolean) {
        super.onWindowFocusChanged(hasFocus)
        player?.onWindowFocusChanged(hasFocus)
    }


    /**
     * 用户点击返回键:
     * 如果是全屏的话,先竖屏.
     * 如果是竖屏,则直接finish
     */
    override fun onBackPressed() {
        if (player?.isFullScreen!!) {
            player?.isFullScreen = false
        } else {
            finish()
        }
    }
}